<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>

    <!--MyHeader-->
    <div th:include="common::MyHeader"></div>
    <!-- End of MyHeader -->

</head>

<body id="page-top">

<!-- Page Wrapper -->
<div id="wrapper">

    <!-- Sidebar -->
    <ul th:replace="common::Sidebar(${session.user.loginName},${session.role.roleName})"></ul>
    <!-- End of Sidebar -->

    <!-- Content Wrapper -->
    <div id="content-wrapper" class="d-flex flex-column">

        <!-- Main Content -->
        <div id="content">

            <!-- Topbar -->
            <div th:include="common::Topbar(${session.user.userName})"></div>
            <!-- End of Topbar -->

            <!-- Begin Page Content -->
            <div class="container-fluid">

                <!-- Page Heading -->
                <div class="d-sm-flex align-items-center justify-content-between mb-4">
                    <h1 class="h3 mb-0 text-gray-800"> 个人信息(Information)</h1>
                </div>


                <!-- Content Column -->
                <div class="row">
                    <div class="col-lg-2">
                        <svg width="10em" height="10em" viewBox="0 0 16 16" class="bi bi-person-fill"
                             fill="currentColor" xmlns="http://www.w3.org/2000/svg">
                            <path fill-rule="evenodd"
                                  d="M3 14s-1 0-1-1 1-4 6-4 6 3 6 4-1 1-1 1H3zm5-6a3 3 0 1 0 0-6 3 3 0 0 0 0 6z"/>
                        </svg>
                    </div>
                    <div class="col-lg-10">
                        <div class="col-lg-4 mb-4">
                            <div class="form-group row">
                                <label for="loginName" class="col-sm-2 col-form-label">账号:</label>
                                <div class="col-sm-10">
                                    <input type="text" readonly class="form-control-plaintext" id="loginName" th:value="${session.user.loginName}">
                                </div>
                            </div>
                            <div class="form-group row">
                                <label for="userName" class="col-sm-2 col-form-label">姓名:</label>
                                <div class="col-sm-10">
                                    <input type="text" readonly class="form-control-plaintext" id="userName" th:value="${session.user.userName}">
                                </div>
                            </div>
                            <div class="form-group row">
                                <label for="sex" class="col-sm-2 col-form-label">性别:</label>
                                <div class="col-sm-10">
                                    <input type="text" readonly class="form-control-plaintext" id="sex" th:value="${session.user.sex}=='0'?'女':'男'">
                                </div>
                            </div>
                        </div>

                        <div class="col-lg-12">
                            <div class="form-row">
                                <div class="form-group col-md-2">
                                    <label for="email">邮箱</label>
                                    <input type="email" class="form-control" id="email" th:value="${session.user.email}">
                                </div>
                                <div class="form-group col-md-2">
                                    <label for="phonenumber">联系电话</label>
                                    <input type="tel" class="form-control" id="phonenumber" th:value="${session.user.phonenumber}">
                                </div>
                            </div>
                            <div class="form-row">
                                <label for="depts"  class="col-sm-2 col-form-label">所属机构</label>
                                <div class="form-group col-md-6">
                                    <input type="text" readonly class="form-control-plaintext" id="depts">
                                </div>
                            </div>

                            <div class="form-group row">
                                <label for="gmtCreat" class="col-sm-2 col-form-label">账号创建日期:</label>
                                <div class="col-sm-6">
                                    <input type="text" readonly class="form-control-plaintext" id="gmtCreat" th:value="${session.user.gmtCreate}">
                                </div>
                            </div>

                            <button onclick="saveBtn()" type="button" class="btn btn-primary">保存</button>

                        </div>
                    </div>
                </div>

            </div>

        </div>
        <!-- /.container-fluid -->

    </div>
    <!-- End of Content Wrapper -->

</div>
<!-- End of Page Wrapper -->

<!-- Scroll to Top Button-->
<a class="scroll-to-top rounded" href="#page-top">
    <i class="fas fa-angle-up"></i>
</a>

<!-- Logout Modal-->
<div th:include="common::LogoutModal"></div>


</body>

</html>

<script>
    $.get(
        "/dept/getAncestorsFrom",
        {},
        function (response) {
            $("#depts").val(response.msg)
        }
    )

    function saveBtn() {
        var userName = $("#userName").val();
        var sex = $("#sex").val();
        var email = $("#email").val();
        var phonenumber = $("#phonenumber").val();
        $.post(
            "/user/alter",
            {
                userName: userName,
                sex: sex,
                email: email,
                phonenumber:phonenumber
            },
            function (data) {
                if (data.code=="0") {
                    alert("更新数据成功！")
                } else {
                    alert("更新数据失败！")
                }
            })

    }
</script>
